const sass  = require('sass')
const loadGruntTasks = require('load-grunt-tasks')


const data = {
    menus: [
      {
        name: 'Home',
        icon: 'aperture',
        link: 'index.html'
      },
      {
        name: 'Features',
        link: 'features.html'
      },
      {
        name: 'About',
        link: 'about.html'
      },
      {
        name: 'Contact',
        link: '#',
        children: [
          {
            name: 'Twitter',
            link: 'https://twitter.com/w_zce'
          },
          {
            name: 'About',
            link: 'https://weibo.com/zceme'
          },
          {
            name: 'divider'
          },
          {
            name: 'About',
            link: 'https://github.com/zce'
          }
        ]
      }
    ],
    pkg: require('./package.json'),
    date: new Date()
  }

module.exports = grunt => {

  
    grunt.initConfig({
        clean: {
            temp: 'dist/**'  // 两个*，连temp都会删除
        },
        // html_template: {
        //     options: {
        //         locals:  data,
        //         beautify: {
        //             indent_size: 2
        //         }
        //     },
        //     build_html: {
        //         options: {
        //             force: false
        //         },
        //         expand: true,
        //         cwd: "src/",
        //         src: "**/*.html",
        //         dest: "dist/"
        //     }
        // },
        // htmlmin: {                                     // Task
        //     dist: {                                      // Target
        //         options: {                                 // Target options
        //             removeComments: true,
        //             collapseWhitespace: true
        //           },
        //           files: {                                   // Dictionary of files
        //             'dist/index.html': 'src/index.html',     // 'destination': 'source'
        //             'dist/about.html': 'src/about.html'
        //           }
        //     },
        //     dev: {                                       // Another target
        //       files: {
        //         'dist/index.html': 'src/index.html',
        //         'dist/about.html': 'src/about.html'
        //       }
        //     }
        //   },
        cssmin: {
            target: {
              files: [{
                expand: true,
                cwd: 'dist/assets/styles',
                src: ['*.css', '!*.min.css'],
                dest: 'dist/assets/styles',
                ext: '.min.css'
              }]
            }
          },
        imagemin: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'src/assets/images',
                    src: ['*.{png,jpg,gif,svg}'],
                    dest: 'dist/assets/images'
                }]
            }
        },
        uglify:{
            main: {
                files: {
                    'dist/assets/scripts/main.js':'dist/assets/scripts/main.js'
                }
            }
        },
        babel: {
            options :{
                sourceMap : true,
                presets: ['@babel/preset-env']
            },
            main:{
                files:{
                    'dist/assets/scripts/main.js':'src/assets/scripts/main.js'
                }
            }
        },
        sass:{
            options :{
                sourceMap : true,
                implementation: sass
            },
            main:{
                files:{
                    'dist/assets/styles/main.css':'src/assets/styles/main.scss'
                }
            }
        },
    })
    
    // grunt.loadNpmTasks('grunt-contrib-clean');
    // grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-babel');

    // 减少 grunt 插件的导入
    loadGruntTasks(grunt)
    grunt.registerTask('default',['clean','sass','babel','uglify','imagemin','cssmin',])

}

